package com.xuduo.amd.controller;

import com.github.pagehelper.PageInfo;
import com.xuduo.amd.dto.ApplicationInfoResp;
import com.xuduo.amd.dto.BusinessRequest;
import com.xuduo.amd.dto.MapRequest;
import com.xuduo.amd.dto.SelectRequest;
import com.xuduo.amd.entity.EamBusinessEntity;
import com.xuduo.amd.pojo.BusinessInfoResp;
import com.xuduo.amd.pojo.EamBusinessBo;
import com.xuduo.amd.pojo.JsonResult;
import com.xuduo.amd.pojo.SelectEntity;
import com.xuduo.amd.service.EamBusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eam")
public class EamBusinessController {
    @Autowired
    private EamBusinessService eamBusinessService;

    /**
     * 基线信息主页面下拉框显示信息
     *
     * @return
     */
    @RequestMapping(value = "/select", method = RequestMethod.GET)
    public JsonResult select() {
        JsonResult jsonResult = new JsonResult();
        Map<String, Object> result = eamBusinessService.select();
        if (!StringUtils.isEmpty(result)) {
            jsonResult.setData(result);

        } else {
            jsonResult.setMessage("查找数据为空");
            jsonResult.setData("");

        }
        return jsonResult;

    }

    /**
     * 基线主页搜索接口
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/findByCondition", method = RequestMethod.POST)
    public JsonResult findByCondition(@RequestBody SelectRequest request) {
        PageInfo<SelectEntity> result = eamBusinessService.findByConditions(request);
        return new JsonResult(result);

    }

    /**
     * 基线架构地图信息全量展示
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/applicationMap", method = RequestMethod.POST)
    public ResponseEntity<Map<String, Map<String, List<String>>>> applicationMap(@RequestBody MapRequest request) {
        Map<String, Map<String, List<String>>> result = eamBusinessService.selectMap(request);
        return new ResponseEntity<Map<String, Map<String, List<String>>>>(result, HttpStatus.OK);
    }


    /**
     * 基线架构地图信息全量展示
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/selectMapByBusiness", method = RequestMethod.POST)
    public ResponseEntity<Map<String, Map<String, List<EamBusinessBo>>>> selectMapByBusiness(@RequestBody MapRequest request) {
        Map<String, Map<String, List<EamBusinessBo>>> result = eamBusinessService.selectMapByBusiness(request);
        return new ResponseEntity<Map<String, Map<String, List<EamBusinessBo>>>>(result, HttpStatus.OK);
    }

    /**
     * 根据id查询基线详情
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/findBusinessInfoByI", method = RequestMethod.GET)
    public JsonResult findBusinessInfoByI(String id) {
        JsonResult jsonResult = new JsonResult();
        BusinessInfoResp result = eamBusinessService.findBusinessInfoById(id);
        jsonResult.setData(result);
        return jsonResult;
    }

    @RequestMapping(value = "/findApplicationInfoById", method = RequestMethod.GET)
    public JsonResult findApplicationInfoById(String id) {
        JsonResult jsonResult = new JsonResult();
        List<ApplicationInfoResp> result = eamBusinessService.FindApplicationInfoById(id);
        jsonResult.setData(result);
        return jsonResult;
    }

    /**
     * 基线应用地图搜索下拉框接口
     * @return
     */
    @RequestMapping(value = "/ApplicationMapSelect",method = RequestMethod.GET)
    public JsonResult ApplicationMapSelect(){
        Map<String,List<String>> result=eamBusinessService.mapSelect();
        if (StringUtils.isEmpty(result)){
            return new JsonResult().setMessage("查询结果为空");

        }else {
            return new JsonResult(result);

        }
    }

    /**
     * 驾驶舱信息展示头部信息接口
     * @return
     */
    @RequestMapping(value = "/ControllerTop",method = RequestMethod.POST)
    public JsonResult ControllerInfo(@RequestBody MapRequest request){
        Map<String,Object> result=eamBusinessService.controllerInfo(request);
        if (!StringUtils.isEmpty(result)){
            return new JsonResult().setData(result);

        }else {
            return new JsonResult().setMessage("查询结果为空");

        }
    }

    /**
     * 驾驶舱信息展示中部信息接口
     * @return
     */
    @RequestMapping(value = "/ControllerMid",method = RequestMethod.POST)
    public JsonResult ControllerMid(@RequestBody MapRequest request){
        Map<String,List<Map<String,Object>>> result=eamBusinessService.findControllerMid(request);
        if (!StringUtils.isEmpty(result)){
            return new JsonResult().setData(result);
        }
        return new JsonResult().setMessage("查询结果为空");

    }


    @RequestMapping(value = "/model",method = RequestMethod.POST)
    public ResponseEntity<Map<String,List<EamBusinessEntity>>> selectModel(@RequestBody BusinessRequest request){
        Map<String,List<EamBusinessEntity>> result = eamBusinessService.selectModel(request);
        return new ResponseEntity<Map<String,List<EamBusinessEntity>>>(result,HttpStatus.OK);

    }

}
